#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e6 + 10;
int n, t;
int degree[N];
int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> t;
    while (t--)
    {
        //memset(degree,0,sizeof degree);
        cin >> n;
        for (int i = 0; i < n - 1; i++)
        {
            int a, b;
            cin >> a >> b;
            degree[a]++, degree[b]++;
        }
        int d = 0;
        for (int i = 1; i <= n; i++)
        {
            //cout<<"degree:"<<degree[i]<<endl;
            d += max(0, degree[i] - 2);
            degree[i] = 0;
        }
        //cout<<"d:"<<d<<endl;
        if (n > 1) cout << d + 2 << endl;
        else cout << 1 << endl;
    }
    return 0;
}